import express, { Router,Express, Request, Response } from "express";
import bodyParser from "body-parser";
import cors from "cors";
import dotenv from "dotenv";
import path from "path";

// Load environment variables from .env file
dotenv.config();

const port: number = Number(process.env.PORT) || 3000; // Ensure PORT is a number

const app: Express = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }))

app.use(express.static(path.join(__dirname, "public")));

// Define a type for the response message
type ResponseMessage = {
  message: string;
};

// app.get("/", (req: Request, res: Response<ResponseMessage>) => {
//   res.json({ message: "HELLO FROM EXPRESS + TS!!!!" }); // Use JSON response
// });

// // Access the example.txt file directly through the public route
// app.get("/getfile", (req: Request, res: Response) => {
//   res.sendFile(path.join(__dirname, "public", "example.txt")); // Ensure the correct path
// });

// Start the server
app.listen(port, () => {
  console.log(`Now listening on http://localhost:${port}`);
});

const router:Router = express.Router();

router.get("/base/get", (req: Request, res: Response) => {
  res.json(req.query); // Use JSON response
})

app.use(router)

// Note: Ensure you have the necessary packages installed
// npm install express body-parser cors dotenv
